
 
package Main;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class ShipSelector extends JPanel {
	private ImageIcon myShip = new ImageIcon("images/GOImages/theShipSmall.png");
	JPanel theShips = new JPanel();
	public ShipSelector(final NewGame theFrame) {
		JLabel ask = new JLabel("Choose a ship:");
		this.add(ask, BorderLayout.NORTH);
		final JLabel chosen = new JLabel("None chosen yet");
		chosen.setForeground(new Color(90, 90, 245));
		this.add(chosen);
		//finish later: use ArrayList which pulls images out of a folder
		this.add(theShips, BorderLayout.CENTER);
		final JButton[] buttons = new JButton[3];
		//must be changed in to a while statement... (action Listeners too)
		for (int x = 0; x < buttons.length; x++) {
			final int b = x + 1;
			buttons[x] = new JButton(myShip);
			theShips.add(buttons[x]);
			buttons[x].addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					chosen.setText(" Ship " + b);
					blackAll(buttons);
					JButton b1 = (JButton) e.getSource();
					b1.setBackground(Color.WHITE);
					theFrame.setReady(true);
				}
			});
		}
		blackAll(buttons);
	}
	void blackAll(JButton[] buttons) {
		for (int x = 0; x < buttons.length; x++) {
			JButton theButton = buttons[x];
			theButton.setBackground(Color.lightGray);
		}
	}
}
